<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
//alert('You liked the URL: ');
var sURL = window.document.URL.toString();  
   var arrParams = sURL.split("/");        
       var sParam =  arrParams[arrParams.length-1];
           xmlhttp.open("POST","http://localhost:90/365f/posts/like",true);
           
           xmlhttp.send(JSON.stringify({id:sParam, time:2}));
xmlhttp.send();
alert('You liked the URL: ');
}


  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '415243725248766',                        // App ID from the app dashboard
      channelUrl : '//localhost:90/maugiaocake/posts', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look fo?phopr social plugins on the page
    });

 FB.Event.subscribe('comment.create', function (response) {
           var sURL = window.document.URL.toString();  
    
       var arrParams = sURL.split("/");        
       var sParam =  arrParams[arrParams.length-1];
       
           xmlhttp=new XMLHttpRequest();
           xmlhttp.open("POST","http://localhost:90/365f/posts/edit",true);
           
           xmlhttp.send(JSON.stringify({id:sParam, time:2}));
            
            alert('You liked the URL: ' + fbcount);

        });

    // Additional initializationfbcount code such as adding Event Listeners goes here
  };
  
  // Load the SDK asynchronously
  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>	
<h1><?php echo h($post['Post']['title']); ?></h1>
<p><?php echo $post['Post']['likes']; ?>
<p><?php echo h($post['Post']['content']); ?></p>
<button type="button" onclick="loadXMLDoc()">Like</button>
<div></div>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<div class="fb-comments" data-href="http://localhost:90/365f/posts/view/<?php echo $post['Post']['_id'];?>" data-width="470"></div>
